package com.example.lenovo.weiyi;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.TextureView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.com.ruanmeng.utils.CommonUtil;
import com.com.ruanmeng.utils.ToolUtils;

import org.w3c.dom.Text;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 注册手机号
 */
public class RegisterPhoneActivity extends BaseActivity {

    @BindView(R.id.ed_register_phone)
    EditText edRegisterPhone;
    @BindView(R.id.li_phone_del)
    LinearLayout liPhoneDel;
    @BindView(R.id.bt_phone_next)
    Button btPhoneNext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register_phone);
        ButterKnife.bind(this);
        AddLoginActivity(this);
        if(TextUtils.isEmpty(getIntent().getStringExtra("forget"))){
            ChangLayTitle("注册");
        }else {
            ChangLayTitle("重置密码");
        }
        LayBack();
        init();
    }

    public void init() {
        edRegisterPhone.addTextChangedListener(this);
        btPhoneNext.setClickable(false);

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        super.onTextChanged(charSequence, i, i1, i2);
        if (edRegisterPhone.getText().toString().length() == 11) {
            btPhoneNext.setBackgroundResource(R.drawable.ed_fullmain);
            btPhoneNext.setClickable(true);
        } else {
            btPhoneNext.setBackgroundResource(R.drawable.ed_fullgeray);
            btPhoneNext.setClickable(false);
        }
        if(TextUtils.isEmpty(edRegisterPhone.getText().toString())){
            liPhoneDel.setVisibility(View.GONE);
        }else {
            liPhoneDel.setVisibility(View.VISIBLE);
        }

    }

    public void doClick(View v) {
        switch (v.getId()) {
            case R.id.bt_phone_next://下一步
                if (TextUtils.isEmpty(edRegisterPhone.getText().toString())) {
                    CommonUtil.showToask(RegisterPhoneActivity.this, "请输入手机号码！");
                    return;
                }
                if (!ToolUtils.isMobileNO(edRegisterPhone.getText().toString())) {
                    CommonUtil.showToask(RegisterPhoneActivity.this, "请输入正确的手机号码！");
                    return;
                }
                Intent in=new Intent(RegisterPhoneActivity.this,GetYanZhengMaActivity.class);
                in.putExtra("forget",getIntent().getStringExtra("forget"));
                in.putExtra("phone",edRegisterPhone.getText().toString());
                startActivity(in);
                break;
            case R.id.li_phone_del:
                edRegisterPhone.setText("");
                liPhoneDel.setVisibility(View.GONE);
                break;
        }
    }
}
